﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace underwater
{
    class Menu
    {
        public static bool isStart = false;
        private int selected = 2;//количество пунктов меню
        //размеры прямоугольников с надписями елементов меню
        public static Rectangle Ret = new Rectangle(Game1.posx, Game1.posy-450, 700, 150);
        public static Rectangle Sta = new Rectangle(Game1.posx, Game1.posy-300, 700, 150);
        public static Rectangle Abo = new Rectangle(Game1.posx, Game1.posy-150, 700, 150);
        public static Rectangle Exi = new Rectangle(Game1.posx, Game1.posy, 700, 150);
        public void Update(ref OS.OpSys os)
        {                        
            MouseState mouse = Mouse.GetState();
            if (mouse.LeftButton == ButtonState.Pressed&&ActivateItem())            
                SelectItem(ref os);  
            //активация элементов меню при наведении на них мыши
            ActivateItem();
        }
        bool ActivateItem()
        {
            if (Cursor.cursorPosition.Intersects(Ret)) { selected = 3; return true; }
            if (Cursor.cursorPosition.Intersects(Sta)) { selected = 2; return true; }
            if (Cursor.cursorPosition.Intersects(Abo)) { selected = 1; return true; }
            if (Cursor.cursorPosition.Intersects(Exi)) { selected = 0; return true; }
            return false;
        }
        //подтверждаем выбор нажатием клавиши мыши на выделеном обекте
        void SelectItem(ref OS.OpSys os)
        {
            switch (selected)
            {
                case 3: { if (isStart) { Game1.State = OSstate.OS; } break; }
                case 2: { Game1.State = OSstate.OS; isStart = true; os = new OS.OpSys(); break; }
                case 1: { Game1.State = OSstate.About; break; }
                case 0: { Game1.State = OSstate.Exit; break; }
            }
        }
        public void Draw(SpriteBatch spritebatch)
        {
            spritebatch.Begin();
            //прорисовка фона в меню
            spritebatch.Draw(Loader.Textures[Game1.txbk], new Rectangle(0, 0, Game1.Width, Game1.Height), new Rectangle(0, 0, Loader.Textures[Game1.txbk].Width, Loader.Textures[Game1.txbk].Height), Color.White);
            // прорисовка логотипа ундерватер    
            double tmp = (double)Game1.Width / (double)Loader.Textures[Game1.txbk].Width;
            double tmp1 = (double)Game1.Height / (double)Loader.Textures[Game1.txbk].Height;
            spritebatch.Draw(Loader.Textures[TextureEnum.Logo],
                new Rectangle(0, 0, (int)((double)Loader.Textures[TextureEnum.Logo].Width*tmp), (int)((double)Loader.Textures[TextureEnum.Logo].Height)),
                new Rectangle(0, 0, Loader.Textures[TextureEnum.Logo].Width, Loader.Textures[TextureEnum.Logo].Height), Color.White);
            //прорисовка елементов меню            
            spritebatch.Draw(!isStart?Loader.Textures[TextureEnum.ReturnDSB]:(selected == 3 ? Loader.Textures[TextureEnum.ReturnACT] : Loader.Textures[TextureEnum.Return]), Ret, Color.White);
            spritebatch.Draw(selected == 2 ? Loader.Textures[TextureEnum.StartACT] : Loader.Textures[TextureEnum.Start], Sta, Color.White);
            spritebatch.Draw(selected == 1 ? Loader.Textures[TextureEnum.AboutACT] : Loader.Textures[TextureEnum.About],Abo, Color.White);
            spritebatch.Draw(selected == 0 ? Loader.Textures[TextureEnum.ExitACT] : Loader.Textures[TextureEnum.Exit],Exi, Color.White); 
            spritebatch.End();        
        }
    }
}
